#include<bits/stdc++.h>
#define y1 Y1
#define fi first
#define endl "\n"
#define se second
#define PI acos(-1)
#define int long long
#define pb(x) push_back(x)
#define PII pair<int, int>
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define _for(i, a, b) for(int i = a; i <= b; ++i)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;

const int N = 2e5 + 10;
int a[N];
int n, k;
queue<PII>q;
int ret[N];
bool st[N];

bool check(int x) {
	return x >= 0 && x <= N;
}

signed main() {
	IOS;
	cin >> n >> k;
	q.push({n, 0});
	st[n] = 1;
	memset(ret, 0x3f, sizeof ret);
	ret[n] = 1;
	while(q.size()) {
		int t = q.front().fi;
		int va = q.front().se;
		q.pop();
		int x1 = t + 1;
		if(check(x1) && ret[x1] > va + 1) {
			st[x1] = true;
			ret[x1] = va + 1;
			q.push({x1, va + 1});
		}
		int x2 = t - 1;
		if(check(x2) && ret[x2] > va + 1) {
			st[x2] = true;
			ret[x2] = va + 1;
			q.push({x2, va + 1});
		}
		int x3 = 2 * t;

		if(check(x3) && ret[x3] > va + 1) {
			st[x3] = true;
			ret[x3] = va + 1;
			q.push({x3, va + 1});
		}
		if(st[k]) {
			cout << ret[k] << endl;
			return 0;
		}
	}
	return 0;
}



